'use strict'

let mydebug = require('./mydebug');
let controller = require('./controllers/controller');

var coap  	= require('coap')
  , server	= coap.createServer()

const { StringDecoder } = require('string_decoder')
const decoder = new StringDecoder('utf8')

server.on('request', function(req, res) {
	var payload = JSON.parse(req.payload)
	mydebug.LogOutput("CoAP request:" + payload)
	controller.sendCmd(payload);
	res.end('')
})

server.listen(function() {
	console.log('Coap server started')
})
